<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>添加会议</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/common/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content="添加会议"/>
    <link rel="stylesheet" href="Css/amazeui.min.css"/>
    <link rel="stylesheet" href="Css/app.css"/>
    <script src="Scripts/api.js"></script>
    <link rel="stylesheet" href="Css/font_783249_3hfdb7m5w0j.css">
    <script src="Scripts/jquery.min.js"></script>
    <script src="Scripts/font_783249_e5yrsf08rap.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script>
    <script>
        BASE_URL = 'https://demo.yiovo.com/';
        STORE_URL = 'index.php?s=/store';
    </script>
    <script>

    </script>
</head>

<body data-type="">
<div class="am-g tpl-g">


    <!-- 内容区域 start -->
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form class="am-form tpl-form-line-form" id="my-form" method="post" novalidate="novalidate">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基本信息</div>

                            </div>
                            <from id="my-from">
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 会议标题 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input name="meeting_title" class="tpl-form-input" id="addtitle" required=""
                                               type="text" value="">
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 会议时间 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input name="meeting_date" class="tpl-form-input" id="adddate" required=""
                                               type="text" value="">
                                        <small>会议时间格式YYYY-MM-DD hh:mm:ss(如，2019-01-29 17:18:05)</small>
                                    </div>
                                </div>


                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 会议主题 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input name="meeting_theme" class="tpl-form-input" id="addtheme" required=""
                                               type="text" value="">
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 会议地点 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input name="meeting_place" class="tpl-form-input" id="addplace" required=""
                                               type="text" value="">
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 会议内容 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <textarea id="addcontent" name="meeting_content" type="text/plain"></textarea>
                                    </div>


                                </div>
                            </from>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button class="j-submit am-btn am-btn-secondary" type="button"
                                    >提交
                                    </button>
                                    <button class="j-back am-btn am-btn-secondary" type="button"
                                    >返回
                                    </button>
                                </div>

                            </div>
                            <div class="am-form-group">

                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        var isUpdate = false;//是否是更新小知识页面的标识
        var isImageChange = false;//是否更改小知识图片
        var isAddImage = false;

        var ue = UE.getEditor('addcontent');

        //图片处理
        var image = '';

        function selectImage(file) {
            if (!file.files || !file.files[0]) {
                return;
            }
            var reader = new FileReader();
            reader.onload = function (evt) {
                document.getElementById('image').src = evt.target.result;
                image = evt.target.result;
                isImageChange = true;
                isAddImage = true;
            }
            reader.readAsDataURL(file.files[0]);
        }


        //获得网址中的参数
        var getParam = function (name) {
            var search = document.location.search;
            var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
            var matcher = pattern.exec(search);
            var items = null;
            if (null != matcher) {
                try {
                    items = decodeURIComponent(decodeURIComponent(matcher[1]));
                } catch (e) {
                    try {
                        items = decodeURIComponent(matcher[1]);
                    } catch (e) {
                        items = matcher[1];
                    }
                }
            }
            return items;
        };
        var wxapphelpid = getParam('meeting_id');
        var oldcreat_time;


        var recallback = function (wxhelpdata) {
            console.log(wxhelpdata);
            isUpdate = true;
            var oldtitle = JSON.stringify(wxhelpdata['meeting_title']).replace(/"/g, "");
            var olddate = JSON.stringify(wxhelpdata['meeting_date']).replace(/"/g, "");
            var oldtheme = JSON.stringify(wxhelpdata['meeting_theme']).replace(/"/g, "");
            var oldplace = JSON.stringify(wxhelpdata['meeting_place']).replace(/"/g, "");
            var oldcontent =wxhelpdata['meeting_content'];
            oldcreat_time = JSON.stringify(wxhelpdata['create_time']);

            var n = parseInt(olddate);
            var odate = new Date(n);
            $("#addtitle").val(oldtitle);
            $("#adddate").val(dateToStr(odate));
            $("#addtheme").val(oldtheme);
            $("#addplace").val(oldplace);
            // $("#addcontent").val(oldcontent);
            ue.addListener("ready", function () {
                ue.setContent(oldcontent);
            });
        };
        if (wxapphelpid != null) {
            getMeetingByid(wxapphelpid, recallback);
        }


        var updatecallback = function (res) {
            if (res.status == 200) {
                alert("提交成功");
                window.location.href = "/admin/Meeting.html";
            } else {
                alert("success:message:" + res.message + ",status:" + res.status);
            }
        };
        var addcallback = function (res) {
            if (res.status == 200) {
                alert("提交成功");
                window.location.href = "/admin/Meeting.html";
            } else {
                alert(res.message + ",status:" + res.status);
            }
        };
        //提交表单
        $('.j-submit').click(function () {

            var mtitle = $("#addtitle").val();
            var tdate = $("#adddate").val();
            var mdate = dateToMs(new Date(Date.parse(tdate)));
            var mtheme = $("#addtheme").val();
            var mplace = $("#addplace").val();
            // var mcontent =  $("#addcontent").val();
            var mcontent = ue.getPlainTxt();

            if (mtitle == "") {
                layer.confirm('请填写会议标题！'
                    , {title: '友情提示'}
                    , function (index) {
                        layer.close(index);
                    }, function () {
                        layer.close();
                    });
            } else if (mdate == "") {
                layer.confirm('请填写会议时间！'
                    , {title: '友情提示'}
                    , function (index) {
                        layer.close(index);
                    }, function () {
                        layer.close();
                    });
            } else if (mtheme == "") {
                layer.confirm('请填写会议主题！'
                    , {title: '友情提示'}
                    , function (index) {
                        layer.close(index);
                    }, function () {
                        layer.close();
                    });
            } else if (mplace == "") {
                layer.confirm('请填写会议地点！'
                    , {title: '友情提示'}
                    , function (index) {
                        layer.close(index);
                    }, function () {
                        layer.close();
                    });
            } else if (mcontent == "") {
                layer.confirm('请填写会议内容！'
                    , {title: '友情提示'}
                    , function (index) {
                        layer.close(index);
                    }, function () {
                        layer.close();
                    });
            } else {

                if (isUpdate) {
                    // var rawdata = '{"meeting_title":"' + mtitle + '","meeting_date":"' + mdate + '","meeting_theme":"' + mtheme + '","create_time":"' + oldcreat_time + '","meeting_place":"' + mplace + '","meeting_content":"' + mcontent + '"}';
                    var data = {
                        "meeting_title": mtitle,
                        "meeting_date": mdate,
                        "meeting_theme": mtheme,
                        "create_time": oldcreat_time,
                        "meeting_place": mplace,
                        "meeting_content": mcontent
                    };

                    updateMeeting(wxapphelpid, JSON.stringify(data), updatecallback);


                } else {
                    // var rawdata = '{"meeting_title":"' + mtitle + '","meeting_date":"' + mdate + '","meeting_theme":"' + mtheme + '","meeting_place":"' + mplace + '","meeting_content":"' + mcontent + '"}';
                    var data = {
                        "meeting_title":  mtitle,
                        "meeting_date":  mdate,
                        "meeting_theme":  mtheme,
                        "meeting_place":  mplace,
                        "meeting_content":  mcontent
                    };
                    addMetting(JSON.stringify(data), addcallback);
                }
            }
        })
        $('.j-back').click(function () {
            window.location.href = "/admin/Meeting.html";
        })


        function dateToMs(date) {
            var result = new Date(date).getTime();
            return result;
        }

        function dateToStr(datetime) {

            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1;//js从0开始取
            var date = datetime.getDate();
            var hour = datetime.getHours();
            var minutes = datetime.getMinutes();
            var second = datetime.getSeconds();

            if (month < 10) {
                month = "0" + month;
            }
            if (date < 10) {
                date = "0" + date;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (second < 10) {
                second = "0" + second;
            }

            var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second; //2009-06-12 17:18:05
            //alert(time);
            return time;
        }

    </script>

</div>

<script src="Scripts/layer.js"></script>
<script src="Scripts/jquery.form.min.js"></script>
<script src="Scripts/amazeui.min.js"></script>
<script src="Scripts/webuploader.html5only.js"></script>
<script src="Scripts/art-template.js"></script>
<script src="Scripts/app.js"></script>
<script src="Scripts/file.library.js"></script>


</body>
</html>